<?php
/**
 * 登录
 * @author zelome@vip.qq.com
 * $Id:$
 */
define('USER', 'admin');
define('PASS', md5('admin'));

require_once('./common.inc.php');
class login extends Action
{
	function doDefault()
	{
		$username = $_COOKIE['sbn_user'];
		$page = $this->app->page();
		$page->params['template'] = 'login.tpl';
		$page->value('username', $username);
		$page->output();
	}
	
	function doLogin()
	{
		$username = trim($_POST['username']);
		$password = $_POST['password'];
		$remember = intval($_POST['remember']);
		
		$db_r = $this->app->orm()->query();
		$db_r->addTable('tb_user');
		$db_r->addField('user_id');
		$db_r->addField('user_name');
		$db_r->addField('user_password');
		$rs = $db_r->getArray();
		
		foreach ($rs as $value){
		
		if($username != $value['user_name'] || md5($password) != md5($value['user_password']))	//数据库验证
		{
			$page = $this->app->page();
			$page->params['template'] = 'login.tpl';
			$page->value('error','用户名或密码错误');
			$page->output();
		}
		else 
		{
			if ($remember === 1)
			{
				setcookie("sbn_user", $username, time() + 30*24*60*60, '/', 'sbnnest.com');
			}
			else
			{
				setcookie("sbn_user", $username, time() - 60, '/', 'sbnnest.com');
			}
			
			session_start();
			$_SESSION['sbn_user']=$username;
			
			$this->app->redirect('index.php');
		}
		}
	}
	
}		
$app->run();

?>
